//
//  PersonInfoModel.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/3/25.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "PersonInfoModel.h"

@implementation PersonInfoModel

+(void)personInfoBook:(PersonInfoModel *)bookInfo completion:(void (^)(BOOL))block
{
    if ([[UserInfo shareUserInfo].userID isEqualToString:@""])
    {
        [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"请先登录", nil)];
        return;
    }
    [SVProgressHUD show];
    NSArray *imgArray;
    if (bookInfo.headImage==nil)
    {
        imgArray = @[];
    }
    else
    {
        imgArray = @[bookInfo.headImage];
    }
    [DKHTTPRequest sendNewDataWithShortUrl:@"userinforeg_2017_"
                                  Param:[XXTool formatStringWithLanguage:[NSString stringWithFormat:@"userid=%@&passwd=%@&username=%@&userphone=%@&usermail=%@&cpname=%@&userposition=%@&usergh=%@&usercountry=%@&usercity=%@&usersex=%@&useradress=%@&userfax=%@&interest=%@",[UserInfo shareUserInfo].userID,[UserInfo shareUserInfo].userPassword,bookInfo.username,bookInfo.userphone,bookInfo.usermail,bookInfo.cpname,bookInfo.userposition,bookInfo.usergh,bookInfo.usercountry,bookInfo.usercity,bookInfo.usersex,bookInfo.useradress,bookInfo.userfax,bookInfo.leibie_index]]
                             ImageArray:imgArray
                                TimeOut:10
                             Completion:^BOOL(NSMutableDictionary *serverDic, DKHTTPResponseType bufferType) {
                                 PersonInfoModel *temp = [PersonInfoModel mj_objectWithKeyValues:serverDic];
                                 if (temp.code==200)
                                 {
                                     NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                                     [user setObject:bookInfo.username forKey:userName];
                                     [user setObject:bookInfo.cpname forKey:userCompany];
                                     [user setObject:temp.head_img forKey:userHeadImgUrl];
                                     [user synchronize];
                                     
                                     [UserInfo shareUserInfo].userName = bookInfo.username;
                                     [UserInfo shareUserInfo].userCompany = bookInfo.cpname;
                                     [UserInfo shareUserInfo].userHeadImgUrl = temp.head_img;
                                     [UserInfo shareUserInfo].leibie=bookInfo.interesting_zh;
                                     
                                     block(YES);
                                 }
                                 else
                                 {
                                     block(NO);
                                 }
                                 return YES;
                             } IsBuffering:NO
                         IsNeedReplaceWrap:NO
     IsUseUpLoadHead:YES];
}

+(void)getPersonInfoWithCompletion:(void (^)(PersonInfoModel *))block
{
    [SVProgressHUD showWithStatus:NSLocalizedString(@"正在获取个人资料", nil)];
    [DKHTTPRequest sendNewDataWithShortUrl:@"userinfoget_2017_"
                                  Param:[XXTool formatStringWithLanguage:[NSString stringWithFormat:@"userid=%@&passwd=%@",[UserInfo shareUserInfo].userID,[UserInfo shareUserInfo].userPassword]]
                             ImageArray:nil
                                TimeOut:10
                             Completion:^BOOL(NSMutableDictionary *serverDic, DKHTTPResponseType bufferType) {
                                 PersonInfoModel *temp = [PersonInfoModel mj_objectWithKeyValues:serverDic];
                                 if (temp.code==200)
                                 {
                                     block(temp);
                                 }
                                 else
                                 {
                                     block(nil);
                                 }
                                 return YES;
                             } IsBuffering:YES
                         IsNeedReplaceWrap:NO
     IsUseUpLoadHead:NO];
}

@end
